home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / wasm223.zip / ANSI.ASM next >
Assembly Source File  |  1993-05-04  |  9KB  |  384 lines

  1. ;**********************;
  2. ; SESSION ANSI Support ;
  3. ;    By Eric Tauck     ;
  4. ;**********************;
  5.  
  6. a_time1 EQU     36      ;first timeout value (for '['), 2 secs
  7. a_time2 EQU     91      ;timeout value, 5 secs
  8.  
  9. a_err1  DB      'Timeout during ANSI sequence',0
  10. a_err2  DB      'Too many ANSI arguments',0
  11. a_err3  DB      'Invalid ANSI command: '
  12. a_err3x DB      '?',0
  13.  
  14. ;--- color mappings
  15.  
  16. a_colors        DB      BLACK, RED, GREEN, BROWN
  17.                 DB      BLUE, MAGENTA, CYAN, WHITE
  18.  
  19. ;========================================
  20. ; Read an ANSI sequence.  Assume ESC has
  21. ; already been read.
  22. ;
  23. ; In: BX= serial record.
  24.  
  25. Ansi_Read PROC  NEAR
  26.         push    di
  27.         push    si
  28.         push    bp
  29.  
  30.         mov     di, bx          ;serial record
  31.         mov     si,OFFSET a_tab ;table
  32.         mov     bp, a_MAX       ;maximum arguments
  33.  
  34. ;--- verify that ESC is really part of ANSI sequence
  35.  
  36.         mov     ax, a_time1     ;first ANSI timeout value
  37.         call    ComWai          ;wait for '['
  38.         jc      ansrea1
  39.         cmp     al, '['         ;check if '['
  40.         je      ansrea2
  41.  
  42. ;--- probably not an ANSI code
  43.  
  44.         mov     bx, di
  45.         call    ComRep          ;replace character after ESC
  46.  
  47. ansrea1 pop     bp
  48.         pop     si
  49.         pop     di
  50.         ret
  51.  
  52. ;--- zero all arguments
  53.  
  54. ansrea2 push    di
  55.         mov     di, si
  56.         mov     cx, bp          ;number of arguments
  57.         sub     al, al          ;store zero
  58.         cld
  59.         rep
  60.         stosb                   ;fill with zeros
  61.         pop     di
  62.         jmps    ansrea5
  63.  
  64. ;=== loop until non-digit
  65.  
  66. ;--- update parameter by digit
  67.  
  68. ansrea3 sub     al, '0'         ;convert to digit
  69.         xchg    al, dl          ;put total in AL
  70.         mov     ah, 10          ;number base
  71.         mul     al, ah          ;total times 10
  72.         add     dl, al          ;new total
  73.  
  74. ;--- wait for character
  75.  
  76. ansrea4 push    dx
  77.         mov     ax, a_time2     ;second ANSI timeout value
  78.         mov     bx, di
  79.         call    ComWai          ;wait for byte
  80.         pop     dx
  81.         jc      ansrea7         ;exit if timeout
  82.  
  83. ;--- process character
  84.  
  85.         cmp     al, '0'         ;lower range of digit
  86.         jb      ansrea6
  87.         cmp     al, '9'         ;upper range of digit
  88.         jbe     ansrea3
  89.         cmp     al, ';'         ;semicolon
  90.         jne     ansrea6
  91.  
  92. ;--- store value
  93.  
  94.         dec     bp              ;decrement argument count (requires n+1 args)
  95.         jz      ansrea8         ;exit if too many arguments
  96.         mov     [si], dl        ;store number
  97.         inc     si              ;increment pointer
  98.  
  99. ansrea5 sub     dl, dl          ;zero current argument
  100.         jmps    ansrea4         ;loop back
  101.  
  102. ;--- command character
  103.  
  104. ansrea6 mov     [si], dl                ;store last number
  105.         mov     dx, si                  ;final address
  106.         sub     dx, OFFSET a_tab        ;subtract start of table
  107.         inc     dx                      ;adjust
  108.         mov     a_cnt, dx               ;save count
  109.  
  110.         mov     bx, di
  111.         call    Ansi_Code               ;process code
  112.         pop     bp
  113.         pop     si
  114.         pop     di
  115.         ret
  116.  
  117. ;--- error
  118.  
  119. ansrea7 mov     ax, OFFSET a_err1       ;timeout
  120.         jmps    ansrea9
  121. ansrea8 mov     ax, OFFSET a_err2       ;too many arguments
  122. ansrea9 call    Command_Error           ;display error message
  123.         pop     bp
  124.         pop     si
  125.         pop     di
  126.         ret
  127.         ENDP
  128.  
  129. ;========================================
  130. ; Substitute minimum arguments (ones) for
  131. ; zeros.
  132. ;
  133. ; In: AH,AL= values.
  134. ;
  135. ; Out: AH,AL= updated.
  136.  
  137. Ansi_Min PROC   NEAR
  138.         sub     dl, dl
  139.         cmp     dl, al
  140.         cmc
  141.         adc     al, 0
  142.         cmp     dl, ah
  143.         cmc
  144.         adc     ah, 0
  145.         ret
  146.         ENDP
  147.  
  148. ;========================================
  149. ; Process an ANSI code and its arguments.
  150. ;
  151. ; In: AL= code; BX= serial record.
  152.  
  153. Ansi_Code PROC  NEAR
  154.         push    di
  155.         push    si
  156.         mov     di, rem_win             ;remote window
  157.         mov     si, bx
  158.  
  159.         mov     dl, al                  ;save command character
  160.         mov     bx, OFFSET a_tab        ;table address
  161.         mov     ax, [bx]                ;load first two arguments
  162.  
  163. ;--- H, f, move cursor
  164.  
  165.         cmp     dl, 'H'
  166.         je      anscod1
  167.         cmp     dl, 'f'
  168.         jne     anscod2
  169.  
  170. anscod1 call    Ansi_Min
  171.         sub     ax, 0101H       ;adjust for local coordinate system
  172.         xchg    al, ah          ;swap row and column
  173.         call    Window_Move
  174.         pop     si
  175.         pop     di
  176.         ret
  177.  
  178. ;--- A, cursor up
  179.  
  180. anscod2 cmp     dl, 'A'
  181.         jne     anscod3
  182.  
  183.         call    Ansi_Min
  184.         call    Window_Up
  185.         pop     si
  186.         pop     di
  187.         ret
  188.  
  189. ;--- B, cursor down
  190.  
  191. anscod3 cmp     dl, 'B'
  192.         jne     anscod4
  193.  
  194.         call    Ansi_Min
  195.         call    Window_Down
  196.         pop     si
  197.         pop     di
  198.         ret
  199.  
  200. ;--- C, cursor right
  201.  
  202. anscod4 cmp     dl, 'C'
  203.         jne     anscod5
  204.  
  205.         call    Ansi_Min
  206.         call    Window_Right
  207.         pop     si
  208.         pop     di
  209.         ret
  210.  
  211. ;--- D, cursor left
  212.  
  213. anscod5 cmp     dl, 'D'
  214.         jne     anscod6
  215.  
  216.         call    Ansi_Min
  217.         call    Window_Left
  218.         pop     si
  219.         pop     di
  220.         ret
  221.  
  222. ;--- s, save cursor location
  223.  
  224. anscod6 cmp     dl, 's'
  225.         jne     anscod7
  226.  
  227.         call    Window_Save
  228.         pop     si
  229.         pop     di
  230.         ret
  231.  
  232. ;--- u, restore cursor location
  233.  
  234. anscod7 cmp     dl, 'u'
  235.         jne     anscod8
  236.  
  237.         call    Window_Rest
  238.         pop     si
  239.         pop     di
  240.         ret
  241.  
  242. ;--- 1J clear to end of screen, 2J clear entire screen
  243.  
  244. anscod8 cmp     dl, 'J'
  245.         jne     anscodB
  246.  
  247.         call    Ansi_Min
  248.         dec     al
  249.         jz      anscod9
  250.         mov     dl, 'J'         ;reload command if error
  251.         dec     al
  252.         jnz     anscodB
  253.  
  254.         call    Window_Clear
  255.         jmps    anscodA
  256.  
  257. anscod9 call    Window_EOS
  258. anscodA pop     si
  259.         pop     di
  260.         ret
  261.  
  262. ;--- K, clear from cursor to end of line
  263.  
  264. anscodB cmp     dl, 'K'
  265.         jne     anscodC
  266.  
  267.         call    Window_EOL
  268.         pop     si
  269.         pop     di
  270.         ret
  271.  
  272. ;--- m, set color
  273.  
  274. anscodC cmp     dl, 'm'
  275.         jne     anscodH
  276.  
  277.         mov     cx, a_cnt               ;load argument count
  278.  
  279. anscodD mov     ah, [bx]                ;load color
  280.         inc     bx
  281.         push    bx
  282.  
  283.         mov     al, ah
  284.         mov     cx, OFFSET Window_Attr  ;attribute set
  285.         cmp     ah, 10                  ;check if attribute set
  286.         jb      anscodF                 ;jump if so
  287.  
  288.         mov     al, ah
  289.         sub     al, 30                  ;convert to foreground color index
  290.         mov     cx, OFFSET Window_Fore  ;color set routine
  291.  
  292.         sub     ah, 40                  ;convert to background color index
  293.         jb      anscodE                 ;jump if not background color
  294.         mov     al, ah
  295.         mov     cx, OFFSET Window_Back  ;color set routine
  296.  
  297. anscodE cmp     al, 7                   ;check upper range
  298.         ja      anscodG                 ;skip if too big
  299.  
  300.         mov     bl, al
  301.         sub     bh, bh
  302.         mov     al, [a_colors+bx]       ;load color
  303.  
  304. anscodF call    cx                      ;set color
  305. anscodG pop     bx
  306.  
  307.         dec     a_cnt
  308.         jnz     anscodD
  309.  
  310.         pop     si
  311.         pop     di
  312.         ret
  313.  
  314. ;--- 6n, device status report (assume '6' argument)
  315.  
  316. anscodH cmp     dl, 'n'
  317.         jne     anscodI
  318.  
  319.         push    bp
  320.         StkAll  bp, 4
  321.  
  322.         mov     al, ESC
  323.         mov     bx, si
  324.         call    ComPut                  ;send ESC
  325.  
  326.         mov     al, '['
  327.         mov     bx, si
  328.         call    ComPut                  ;send bracket
  329.  
  330.         call    Window_Position         ;get position
  331.         add     ax, 0101H               ;adjust
  332.         push    ax                      ;save column
  333.  
  334.         mov     al, ah
  335.         sub     ah, ah
  336.         sub     dx, dx
  337.         mov     cx, 10
  338.         mov     bx, bp
  339.         call    Num2Str                 ;convert to string
  340.         mov     ax, bp
  341.         call    StrLen                  ;get length
  342.         mov     cx, ax
  343.         mov     ax, bp
  344.         mov     bx, si
  345.         call    ComWri                  ;write string
  346.  
  347.         mov     al, ';'
  348.         mov     bx, si
  349.         call    ComPut
  350.  
  351.         pop     ax
  352.         sub     ah, ah
  353.         sub     dx, dx
  354.         mov     cx, 10
  355.         mov     bx, bp
  356.         call    Num2Str                 ;convert to string
  357.         mov     ax, bp
  358.         call    StrLen                  ;get length
  359.         mov     cx, ax
  360.         mov     ax, bp
  361.         mov     bx, si
  362.         call    ComWri                  ;write string
  363.  
  364.         mov     al, 'R'
  365.         mov     bx, si
  366.         call    ComPut                  ;send R
  367.  
  368.         StkRel  4
  369.         pop     bp
  370.  
  371.         pop     si
  372.         pop     di
  373.         ret
  374.  
  375. ;--- invalid ANSI code
  376.  
  377. anscodI mov     a_err3x, dl             ;save command
  378.         mov     ax, OFFSET a_err3
  379.         call    Command_Error           ;display error message
  380.         pop     si
  381.         pop     di
  382.         ret
  383.         ENDP
  384.